package exams;

/**
 * Created by pc on 2015/5/15.
 */
public class ShortestBinarian {

    public int log(double value, double base) {
      return (int) (Math.log(value) / Math.log(base));
    }

    public int solution (int [] A) {
        //calculate sum of given A
        int sum = 0;
        for (int ele: A){
            sum += Math.pow(2, ele);
        }
        System.out.println("total is: " + sum);

        int maxLen = 1;
        int temp = log(sum, 2);
        int ramain = (int) (sum - Math.pow(2, temp));
        while (ramain > 0){
            temp = log(ramain, 2);
            ramain = (int) (ramain - Math.pow(2, temp));
            maxLen++;
        }

        return maxLen;
    }

    public static void main(String args[]){
        ShortestBinarian sb = new ShortestBinarian();
        System.out.println("len: " + sb.solution(new int[] {1, 5, 2, 3, 1, 2}));
//        System.out.println("get: " + sb.log(512, 2));
//        System.out.println("get: " + sb.log(13, 2));
    }
}
